<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <%--    <meta name="viewport" content="width=device-width, initial-scale=1" />--%>
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>职位列表</title>
    <style>

        img { width: 100%; }


        .position-jobname{
            display: flex;
            word-break: normal;
            overflow: hidden;
            font-size: 16px;
            color: #333;
            font-weight: bold;
            width: 88%;
            padding-right: 25px;
        }
        .position-company{
            line-height: 30px;
        }
        .position-base-info{
            font-size: 14px;
            color: #999;
            line-height: 30px;

        }

        .position-base-info_city{
            color: #C0C0C0;
            display: inline;
            font-size: 10px;
            padding: 0.3rem;
        }
        .position-base-info_domain {
            color: #C0C0C0;
            display: inline;
            font-size: 10px;
            padding: 0.3rem;
        }
        .position-base-info_date{
            color: #C0C0C0;
            display: inline;
            font-size: 10px;
            padding: 0.3rem;
        }
        .position-base-info_salary{
            float: right;
            font-size: 14px;
        }
    </style>
</head>
<body>
<div>
    <img src="${ctx}/resources/images/jobBanner.jpg">
</div>
<div class="ui segment" id="btn-next2">
    <div class="fluid ui button" id="next" >创建校招项目</div>
</div>
<div  id="n-page">

    <div id="row-data" >
        <c:forEach items="${joblist}" var="jd">
            <div class="position" data-position-id="${jd.id}">
                <div class="position-jobname">
                    ${jd.name}
                </div>
                <div class="position-company">
                    ${jd.companyName}
                </div>
                <div class="position-base-info">
                    <div class="position-base-info_city">
                       ${jd.cityName}
                    </div>
                    <div class="position-base-info_domain">
                       ${jd.specialtyName}
                    </div>
                    <div class="position-base-info_salary">${jd.createDateStr}</div>
                </div>

                <hr class="hrtext"/>
            </div>
        </c:forEach>
    </div>

</div>

<!-- 测试用，正式发布关闭
<div id="testid">
点击获取更多数据
</div>
-->
<input type="hidden" name="lastposition" id="lastjob" value="${fn:length(joblist)}"/>
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

    wx.config({
        debug: false,
        appId: "${config.appid}",
        timestamp: ${config.currenttimestamp},
        nonceStr: "${config.nonceStr}",
        signature: "${config.signatureStr}",
        jsApiList: ['checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'showOptionMenu']
    });

    var datasource = {
        moredata: function() {
            var getUrl = '${ctx}/wechat/hunter/school/schJob/page';
            var offset  = $('#lastjob').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "?offset=" + offset;
            var boxie=document.querySelector("#row-data");
            var pe=document.createElement("p");
            // pe.innerHTML="---不好意思，已经没有更多数据了---";
            if(hasmore != "yes"){
                // boxie.appendChild(pe);
                alert("---不好意思，已经没有更多数据了---");
                return;
            }
            var that = this;

            $.ajax({
                url: getUrl,
                type: "GET",
                success: function(data, status){
                    if(data.errorcode == "0") {
                        that.appenddata(data);
                    } else {
                        var errorUrl = '${ctx}/wechat/headhunter/error.page';
                        location.href = errorUrl;
                    }
                },
                error: function(){
                    alert("服务出错，请稍后尝试");
                }
            });
        },

        appenddata:function(data) {
            var offset = parseInt($('#lastjob').val());
            var divstring = "";
            var joblist = data.data;

            var count = joblist.length;
            offset += parseInt(count);
            $('#lastjob').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
            }

            for (var i in joblist) {
                var jd = joblist[i];
                divstring += "<div class='position' data-position-id='"+jd.id+"'>";
                divstring += "<div class='list-row'>";
                divstring += "<div class='list-position-1-1'>";
                divstring += jd.name;
                divstring += "</div>";
                divstring += "<div class='list-position-1-2'>";
                divstring += jd.city.name
                divstring += "</div>";
                divstring += "<div class='list-position-1-3'>";
                divstring += jd.expiredDateStr;
                divstring += "</div>";
                divstring += "</div>";
                divstring += "<hr class='hrtext'/>";
                divstring += "</div>";

            }
            var newdata = $(divstring);
            $('#row-data').append(newdata);

        }
    };

    $(document).ready(function() {
        var l = sessionStorage.getItem('index_list');

        if(null !== l && '' !== l){
            $("#row-data").html(l);
            $(window).scrollTop(sessionStorage.getItem('index_scroll'));
            page = sessionStorage.getItem('index_page');
            sessionStorage.removeItem('index_list');
            sessionStorage.removeItem('index_scroll');
        }else{
            // datasource.moredata();
        };

        $(window).scroll(function() {
            if($(window).scrollTop() == $(document).height() - $(window).height()) {
                // datasource.moredata();
            }
        });

        $('#row-data').on('click','.position', function() {
            var offset  = parseInt($('#lastjob').val());
            var positionid = $(this).attr('data-position-id');
            console.log("jobId:"+positionid)
            var getUrl = '${ctx}/wechat/hunter/school/schJob/get?id='+positionid;
            sessionStorage.setItem('index_list',$("#row-data").html());
            sessionStorage.setItem('index_page',offset);
            sessionStorage.setItem('index_scroll',$(window).scrollTop());
            window.location.href = getUrl;
        });

        $('#next').on('click',function () {
            console.log("创建项目");
            location.href = "${ctx}/wechat/hunter/school/schJob/add"
        })

        wx.ready(function() {
            wx.onMenuShareAppMessage({
                title: 'Headoffer--专业招聘平台----推荐有奖！',
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--专业招聘平台----推荐有奖！',
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });

            wx.showOptionMenu();

        });

    });

    $(function(){

        var imglist =document.getElementsByTagName("img");
//安卓4.0+等高版本不支持window.screen.width，安卓2.3.3系统支持
        /*
        var _width = window.screen.width;
        var _height = window.screen.height - 20;
        var _width = document.body.clientWidth;
        var _height = document.body.clientHeight - 20;
        */
        var _width,
            _height;
        doDraw();

        window.onresize = function(){
            doDraw();
        }

        function doDraw(){
            _width = window.innerWidth;
            _height = window.innerHeight - 20;
            for( var i = 0, len = imglist.length; i < len; i++){
                DrawImage(imglist[i],_width,_height);
            }
        }

        function DrawImage(ImgD,_width,_height){
            var image=new Image();
            image.src=ImgD.src;
            image.onload = function(){
                if(image.width>30 && image.height>30){

                    if(image.width/image.height>= _width/_height){
                        if(image.width>_width){
                            ImgD.width=_width;
                            ImgD.height=(image.height*_width)/image.width;
                        }else{
                            ImgD.width=image.width;
                            ImgD.height=image.height;
                        }
                    }else{
                        if(image.height>_height){
                            ImgD.height=_height;
                            ImgD.width=(image.width*_height)/image.height;
                        }else{
                            ImgD.width=image.width;
                            ImgD.height=image.height;
                        }
                    }
                }
            }

        }

    });


</script>
</body>
</html>